#ifndef FTK_XUL_H
#define FTK_XUL_H

#include <QtGui>

#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <assert.h>

#define ftk_atof atof
#define ftk_itoa(buf, len, value) itoa(value, buf, 10)
#define ftk_strtol strtol

#define return_if_fail(p)          if(!(p)) { qDebug("%s:%d "#p" failed.n", __func__, __LINE__); return;}
#define return_val_if_fail(p, val) if(!(p)) { qDebug("%s:%d "#p" failed.n", __func__, __LINE__); return (val);}

double ftk_expr_eval(const char* expr);

class FtkXul {
public:
    FtkXul();
    const char* ftk_preprocess_value(QWidget *widget, const char* value);

    inline void setDisplayWidth(int width)
    {
        displayWidth = width;
    }

    inline void setDisplayHeight(int height)
    {
        displayHeight = height;
    }

    inline void setWindowWidth(int width)
    {
        windowWidth = width;
    }

    inline void setWindowHeight(int height)
    {
        windowHeight = height;
    }

    inline int getWindowWidth(void)
    {
        return windowWidth;
    }

    inline int getWindowHeight(void)
    {
        return windowHeight;
    }

private:
    int ftk_find_const(const char* name);
    int ftk_find_const_value(const char* name);
    int ftk_find_getter(const char* name);
    const char* ftk_get_getter_name(int i);
    int ftk_get_getter_value(QWidget *widget, int i);

    inline int ftk_get_parent_width(QWidget *widget)
    {
        return widget->parentWidget()->width();
    }

    inline int ftk_get_parent_height(QWidget *widget)
    {
        return widget->parentWidget()->height();
    }

    inline int ftk_get_window_width(QWidget *widget)
    {
        return windowWidth;
    }

    inline int ftk_get_window_height(QWidget *widget)
    {
        return windowHeight;
    }

    inline int ftk_get_display_width(QWidget *widget)
    {
        return displayWidth;
    }

    inline int ftk_get_display_height(QWidget *widget)
    {
        return displayHeight;
    }

    static int  displayWidth;
    static int  displayHeight;
    static int  windowWidth;
    static int  windowHeight;
};

#endif // FTK_XUL_H
